package com.kujie.access.controller;

import cn.hutool.core.lang.tree.Tree;
import com.kujie.access.domain.po.RegionManagement;
import com.kujie.access.domain.vo.RegionManagementVO;
import com.kujie.access.service.IRegionService;
import com.kujie.common.core.domain.R;
import com.kujie.common.encrypt.annotation.ApiEncrypt;
import com.kujie.common.web.core.BaseController;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 区域管理 api
 *
 * @author ck
 * @date 2025-05-26
 */
@Slf4j
@RestController
@RequestMapping("/region")
@RequiredArgsConstructor
@ApiEncrypt(response = true)
public class RegionController extends BaseController {
    private final IRegionService regionService;

    @GetMapping("/list")
    public R<List<Tree<String>>> list(RegionManagement regionManagement) {
        return R.ok(regionService.list(regionManagement));
    }

    @DeleteMapping("/delete/{indexCode}")
    public R<?> delete(@PathVariable String indexCode) {
        return toAjax(regionService.delete(indexCode));
    }

    @PostMapping("/insertOrUpdate")
    public R<?> insertOrUpdate(@RequestBody RegionManagement regionManagement) {
        return toAjax(regionService.insertOrUpdate(regionManagement));
    }

    @GetMapping("/detail")
    public R<RegionManagementVO> detail(String indexCode) {
        return R.ok(regionService.detail(indexCode));
    }

}
